<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>填写预计上门时间</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<style>
			.selectDate{
				color: #333;
			}
			.inline-block{
				color: #999999;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">填写预计上门时间</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="clum">
					<span class="name">服务编号</span>
					<span class="txt" id="serviceNo"></span>
				</div>
				<div class="clum">
					<span class="name">服务角色</span>
					<span class="txt">
						<input class="serviceRole" name="serviceRole" type="radio" value="1" disabled="disabled">现场服务&nbsp;&nbsp;
						<input class="serviceRole" name="serviceRole" type="radio" value="2" disabled="disabled">实习
					</span>

				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="pjcgqd">
						<em>查看计划安排</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="clum">
					<span class="name">预计上门时间<em class="t_red">*</em></span>
					<button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum">
					<span class="name">预计工时<em class="t_red">*</em></span>
					<input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
				</div>
				<div class="clum">
					<span class="name">预计离开时间<em class="t_red">*</em></span>
					<span class="txt" id="estimatedDepartureTime">自动计算</span>
					<!-- <input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled"/> -->
				</div>
			</div>
			<div class="btn_box">
				
				<span class="fl" id="cancel">取消</span>
				<span class="fr red" id="save">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		
		<script type="text/javascript" charset="utf-8">
			var ServiceNoticeId
			var serviceNo
			var planId
			var serviceRole
			var estimatedVisitingTime
			var estimatedWorkingHours
			var estimatedDepartureTime
			
			 //mui初始化
			(function($, doc) {
				$.init();
				
				// 取消方法
				h("#cancel").tap(function(){
					$.back()
				});
				
				new Rolldate({
					el: '#estimatedVisitingTime',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择预计上门时间',
					},
					confirm: function(date) {
						jisuan(date)
					}
				})
				
				$.plusReady(function() {
					
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 ServiceNoticeId = self.ServiceNoticeId;
					 serviceNo = self.serviceNo;
					 planId = self.planId;
					 serviceRole = self.serviceRole;
					 h("#serviceNo").html(serviceNo)
					 
					 if (serviceRole) {
						 document.querySelector(`input[name='serviceRole'][value='${serviceRole}']`).checked=true;
					 }
					
					// 保存
					h("#save").tap(function() {
						app.showWaiting('正在提交...')
						// 调用计算方法
						jisuan('1');
						estimatedVisitingTime = h("#estimatedVisitingTime").html();
						if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
							app.closeWaiting()
							app.toast("请选择预计上门时间");
							return
						}
						estimatedWorkingHours = h("#estimatedWorkingHours").val();
						if(estimatedWorkingHours==null || estimatedWorkingHours==""){
							app.closeWaiting()
							app.toast("请输入预计工时");
							return
						}
						estimatedDepartureTime = h("#estimatedDepartureTime").html();
						saveIn();
						
					});
					
					// 查看计划安排
					h("#pjcgqd").tap(function() {
						app.jumpTo("/view/service/taskDetails/task_details.html", "view/service/taskDetails/task_details.html",
							{
								serviceNoticeId:ServiceNoticeId,
								serviceNo:serviceNo,
								enginnerId: app.getUser().enginnerId,
							}
						);
					});
					
					var saveIn = function(){
						
						ajaxGet(BASE_URL + "cc/PlanDetails/updatefseAccept", {
							"ServiceNoticeIds": ServiceNoticeId,
							"serviceNos": serviceNo,
							"planIds": planId,
							"EnginnerId": app.getUser().enginnerId,
							"enginnerName": app.getUser().name,
							"serviceRole": serviceRole,
							"StartTime": estimatedVisitingTime,
							"workingHours": estimatedWorkingHours,
							"EndTime": estimatedDepartureTime
						}, function(data) {
							app.closeWaiting()
							console.log(JSON.stringify(data))
							if(data.code==200){
								app.toast("保存成功")
								// 查找上级页面并关闭页面
								var signOutVisitAgain = plus.webview.getWebviewById('view/service/notice/signOutVisitAgain.html');
								if (signOutVisitAgain) {
									signOutVisitAgain.close()
								}
								// 查找上级页面并关闭页面
								var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
								if (completedList) {
									completedList.close()
								}
								// 查找上级页面并关闭页面
								var details = plus.webview.getWebviewById('view/service/accept/details.html');
								if (details) {
									details.close()
								}
								var acceptList = plus.webview.getWebviewById('view/service/assign/acceptList.html');
								if (acceptList) {
									acceptList.close()
								}
								
								// 关闭进行中
								var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
								if(conductList){
									conductList.close()
								}
								
								// 关闭工作台查询未关闭服务通知列表
								var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
								if(notClosedList){
									notClosedList.close()
								}
								
								// 1、刷新FSE首页
								var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
								if(indexFSE){
									indexFSE.evalJS('getList("1")')
								}
								
								// 关闭工作台已接受列表
								var acceptedList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
								if(acceptedList){
									acceptedList.close()
								}
								
								// 5、已签离
								var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
								if(checkedOutList){
									checkedOutList.evalJS('getList()')
									self.close();
									mui.back();
								}else{
									var checkedOutList1 = plus.webview.create('/view/service/notice/checkedOutList.html','view/service/notice/checkedOutList.html')
									checkedOutList1.show()
									self.close()
								}

							}
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
						});
					}
					
				});
				
			}(mui, document));
			
			// 自动计算方法
			function jisuan(date){
				var estimatedVisitingTime;
				if(date!="1"){
					estimatedVisitingTime = date
				}else{
					estimatedVisitingTime = h("#estimatedVisitingTime").html();
				}
				if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
					return
				}
				var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
				var estimatedWorkingHours = h("#estimatedWorkingHours").val();
				if(estimatedWorkingHours==null || estimatedWorkingHours==""){
					return
				}
				var edt = evt + estimatedWorkingHours * 60 *60 * 1000;
				var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
				h("#estimatedDepartureTime").html(estimatedDepartureTime);
			}
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
